//
//  IPNavigationController.swift
//  IPlan
//
//  Created by robot on 3/19/16.
//  Copyright © 2016 codeFighter.com. All rights reserved.
//

import UIKit

class IPNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    // custom the backBarButtonItem
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        let backButton = UIButton()
        backButton.frame = CGRect(x: 0, y: 0, width: 31, height: 21)
        backButton.setImage(UIImage(named: "top_back_arrowfense"), for: UIControlState())
        // Change the location of the images's location.
        if IS_IPHONE_4{
    
            backButton.imageEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 0)
        }else if IS_IPHONE_5{
        
           backButton.imageEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 0)
        }else if IS_IPHONE_6{
        
           backButton.imageEdgeInsets = UIEdgeInsetsMake(0, -23, 0, 0)
        }else if IS_IPHONE_6P{
        
           backButton.imageEdgeInsets = UIEdgeInsetsMake(0, -32, 0, 0)
        }

        viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backButton)
        backButton.addTarget(self, action: #selector(IPNavigationController.backButtonAction(_:)), for: UIControlEvents.touchUpInside)
        super.pushViewController(viewController, animated: animated)
        
    }

    func backButtonAction(_ clickedButton:UIButton) ->Void{
    
       popViewController(animated: true)
    
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
